home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 1 / Gold Medal Software Volume 1 (Gold Medal) (1994).iso / prog / dasv10_.arj / CRAPS.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-08  |  2.9 KB  |  144 lines

  1. // 'Craps' game by David Scouten
  2. // 1993 DAS Software Publications
  3.  
  4. #include <conio.h>
  5. #include <dos.h>
  6. #include <iostream.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <time.h>
  10.  
  11. int two_dice(int,int,int,int,char[]);
  12. void display_results(int,int,int);
  13. FILE *infptr, *outfptr;
  14.  
  15. void main()
  16. {//begin main program
  17.  
  18.     int gamestats, sum, point, dis1, dis2, win=0, lose=0;
  19.     int bet, money=100;
  20.  
  21. clrscr();
  22.     cout<<"\nCraps by David Scouten";
  23.     cout<<"\n1993 DAS Software Publications\n";
  24.     cout<<"\nDisplay just dice (y/n) ? ";
  25.     if (getche()=='y') //begin if
  26.         dis1 = 1;
  27.     else //else
  28.         dis1 = 0;
  29.     // end if
  30.     cout<<"\nDisplay just totals (y/n) ? ";
  31.     if (getche()=='y') //begin if
  32.         dis2 = 1;
  33.     else //else
  34.         dis2 = 0;
  35.     //end if
  36.     cout<<"\nLoad game ? (y/n): ";
  37.     if (getche()=='y') // begin if
  38.         goto LOADGAME;
  39.     else // else
  40.         goto INBET;
  41.     // end if
  42.  
  43. PLAYAGAIN:
  44.  
  45.     if (money<=0) {//begin if
  46.         win=0; lose=0; money=100;
  47.     }//end if
  48.  
  49. INBET:
  50. clrscr();
  51.     display_results(win,lose,money);
  52.     cout<<"\nEntering '0' will quit game";
  53.     cout<<"\nWhat is your bet ? ";
  54.     cin>>bet;
  55.     if (bet>money) {//begin if
  56.         cout<<"\nYou don't have enough!";
  57.         goto INBET;
  58.     }//else if
  59.     else if (bet<=0) {
  60.             goto ENDGAME;
  61.     }//end if
  62.  
  63.     srand(clock());
  64.     cout<<"\n";
  65.     sum = two_dice(6,100,dis1,dis2,"Player rolled: ");
  66.     cout<<"\n";
  67.  
  68.     switch (sum) {//begin case switch
  69.  
  70.         case 7: case 11:
  71.             gamestats = 1;
  72.             break;
  73.         case 2: case 3: case 12:
  74.             gamestats = 2;
  75.             break;
  76.         default:
  77.             gamestats = 0;
  78.             point = sum;
  79.             cout<<"Point is "<<point<<"\n\n";
  80.             break;
  81.     }//end switch
  82.     while (gamestats == 0) {//begin while
  83.             sum = two_dice(6,100,dis1,dis2,"Player rolled: ");
  84.             cout<<"\n";
  85.  
  86.             if (sum == point) {//begin if
  87.                 cout<<"You made Point!\n";
  88.                 gamestats = 1;
  89.             } else if (sum == 7) {//else if
  90.                      gamestats = 2;
  91.             }//end if
  92.     }//end while
  93.     if (gamestats == 1) {//begin if
  94.         cout<<"\nPlayer wins";
  95.         win+=1; money+=bet;
  96.     }
  97.     else //else
  98.     {
  99.         cout<<"\nPlayer loses";
  100.         lose+=1; money-=bet;
  101.     }//end if
  102.  
  103.     display_results(win,lose,money);
  104.     if (money<=0) {//begin if
  105.         cout<<"\nYou have no more money!";
  106.         cout<<"\nPlay again (y/n) ? ";
  107.         if (getche()=='y') {//begin if
  108.             clrscr();
  109.             goto PLAYAGAIN;
  110.         }
  111.         else //else
  112.         {
  113.             cout<<"\n";
  114.             goto ENDGAME;
  115.         }//end if
  116.     }//end if
  117.  
  118.     cout<<"\nSave game ? (y/n): ";
  119.     if (getche()=='y') //begin if
  120.         goto SAVEGAME;
  121.     else // else
  122.         goto INBET;
  123.     // end if
  124.  
  125. SAVEGAME:
  126.     if ((outfptr=fopen("craps.dat","w"))==NULL) {//check for data file
  127.         cout<<"Error opening 'craps.dat' file.\n";
  128.     }//end if
  129.     fprintf(outfptr,"%d %d %d",win,lose,money);
  130.     fclose(outfptr);
  131. goto INBET;
  132.  
  133. LOADGAME:
  134.     if ((infptr=fopen("craps.dat","r"))==NULL) {//check for data file
  135.         cout<<"Error opening 'craps.dat' file.\n";
  136.     }//end if
  137.     fscanf(infptr,"%d %d %d",&win,&lose,&money);
  138.     fclose(infptr);
  139. goto INBET;
  140.  
  141. ENDGAME:
  142.     cout<<"\nSee ya' later!";
  143. }//end main program
  144.